/**
 * @author iello-dev
 */
function timeToHuman(sUnixTime){
    var theDate = new Date(sUnixTime * 1000);
    dateString = theDate.toGMTString();
    arrDateStr = dateString.split(" ");
    //    document.form1.inMon.value = getMonthNum(arrDateStr[2]);
    //    document.form1.inDay.value = arrDateStr[1];
    //    document.form1.inYear.value = arrDateStr[3];
    //    document.form1.inHr.value = arrDateStr[4].substr(0,2);
    //    document.form1.inMin.value = arrDateStr[4].substr(3,2);
    //    document.form1.inSec.value = arrDateStr[4].substr(6,2);
    return arrDateStr[1] + '-' + getMonthNum(arrDateStr[2]) + '-' + arrDateStr[3];
}
function getMonthNum(abbMonth){
    var arrMon = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    for (i = 0; i < arrMon.length; i++) {
        if (abbMonth == arrMon[i]) 
            return i + 1;
    }
}
function pipeCallback(obj){
    jQuery(document).ready(function(){
        var html = '<ul id="rss-feeds">';
        var content = new Array;
        var excerpt = '';
        var max_number = 30;
        
        console.log(obj);
        
        if (obj && (jQuery('#agregator').length > 0)) {
            for (x = 0; x < obj.count; x++) {
                html += '<li><h3><a href="' + obj.value.items[x].link + '">' + obj.value.items[x].title + '</a></h3>';
                content = obj.value.items[x].description.split(' ');
                for (y = 0; y < max_number; y++) {
                    excerpt += content[y] + ' ';
                }
                html += '<p>' + excerpt + '[...]</p>';
                html += '<p><span class="rss-published">Published' + timeToHuman(obj.value.items[x].published.utime) + '</span></p></li>';
                //clear var
                excerpt = '';
            }
        }
        html += '</ul>';
        jQuery('#agregator').html(html);
    });
}
/* JQUERY RULES */
jQuery.noConflict();

jQuery(document).ready(function(){
	/**
	 * gp-iello
	 * thumbnailing daily guest picture
	 */
	if (jQuery('.daily-guest img').length > 0) {
		jQuery('.daily-guest img').jScale({ls:'200px'}, function(){
				jQuery(this).wrap('<div class="thumb-img"><div class="thumb-inner">' + '</div><div class="thumb-strip"></div><div class="thumb-zoom"></div></div>');	
				jQuery(this).css('position','absolute');
				jQuery(this).css('left', '-' + ( parseInt( jQuery(this).width() ) / 2 ) + 'px' );
				jQuery(this).css('top', '-' + ( parseInt( jQuery(this).height() ) / 2 ) + 'px' );
				jQuery(this).css('margin-left', '50%' );
				jQuery(this).css('margin-top', '50%' );				
		})
	}
	/**
	 * gp-iello
	 * thumbnailing post images and floating them to the left (and clear:left)
	 * 
	 */
	if (jQuery('div.post img').length >0) {
		jQuery('div.post img').each(function(){
			jQuery(this).jScale({ls:'150px'}, function(){
				jQuery(this).wrap('<div class="thumb-img"><div class="thumb-inner">' + '</div><div class="thumb-strip"></div><div class="thumb-zoom"></div></div>');	
				jQuery(this).css('position','absolute');
				jQuery(this).css('left', '-' + ( parseInt( jQuery(this).width() ) / 2 ) + 'px' );
				jQuery(this).css('top', '-' + ( parseInt( jQuery(this).height() ) / 2 ) + 'px' );
				jQuery(this).css('margin-left', '50%' );
				jQuery(this).css('margin-top', '50%' );				
			});		
		});
	}
	if (jQuery('div.post-photo img').length >0) {
		jQuery("div.post-photo img").thumbs();
		jQuery("div.post-photo img").thumbsImg();
	}
    
    
//    if (jQuery('#agregator').length > 0) {
//        // call yahoo pipes where XXXXX is your pipe application id, asking yahoo to return it as json and passing the callback function
//        jQuery.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_id=uk9z8qsx3hGZrJOUggSecQ&_render=json&_callback=?", function(data){
//            // data here is the JSON object with count, value (feed entries are inside the value property)</code>
//            var html = '<ul id="rss-feeds">';
//            var content = new Array;
//            var re = /<img(\s+)(.+?)>/ig;
//            var excerpt = '';
//            var max_number = 30;
//			var datearr = new Array();
//			var postdate ='';
//            
//            //console.log(data);
//            
//            jQuery.each(data.value.items, function(i, item){
//                // this function will be called for each entry
//                // i is the count starting from zero, item is the feed entry
//                // e.g. item.title will return the feed title and so on                
//                // console.log(item.pubDate);
//                if (item) {
//                    //datearr = item.pubDate.replace(',','').split(" ");
//					//console.log(datearr[0]);							
//
//                    html += '<li><h3><a target="_blank" href="' + item.link + '">' + item.title + '</a></h3>';
//                    content = item.description.split(" ");
//					if (content.length >= max_number) {
//	                    for (y = 0; y < max_number; y++) {
//							excerpt += content[y] + " ";
//						}
//					}
//					else {
//						excerpt = item.description;
//					}
//                    html += '<p>' + excerpt + '[...]</p></li>';
//                    //html += '<p><span class="rss-published">Published:</span> ' + postdate + '</p></li>';
//                }
//            });
//            html += '</ul>';
//            jQuery('#agregator').html(html);
//        });
//    }
});